<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>重置密码</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/default/layer.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <form class="form-horizontal m-t" id="commentForm">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label class="col-xs-3 control-label">新密码：</label>
                                            <div class="col-xs-9">
                                                <input type="password" class="form-control NewPWD" name="NewPWD" placeholder="请输入新密码"  aria-required="true" id="NewPWD">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label class="col-xs-3 control-label">确认密码：</label>
                                            <div class="col-xs-9">
                                                <input type="password" class="form-control confirm_password" name="confirm_password" placeholder="确认新密码" aria-required="true">
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-xs-3 col-xs-offset-3">
                                    <button class="btn btn-success" type="submit">确定</button>
                                </div>
                                <div class="col-xs-3">
                                    <button class="btn btn-danger" type="submit">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- 自定义js -->
    <script src="js/content.js"></script>
    <script src="js/plugins/layer/layer.min.js"></script>
    <script src="js/plugins/layer/layer.js"></script>
    <script src="js/plugins/validate/jquery.validate.min.js"></script>
    <script src="js/plugins/validate/messages_zh.min.js"></script>
    <script src="js/work/common.js"></script>
    <script>
         var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        $(document).ready(function () {
            $("#commentForm").validate({
                    rules: {
                        NewPWD: {
                            required: true,
                            minlength: 6,
                            maxlength:18
                        },
                        confirm_password: {
                            required: true,
                            minlength: 6,
                            maxlength:18,
                            equalTo: "#NewPWD"
                        }
                    }

                })
           
            $(".btn-danger").on("click", function () {
                parent.layer.close(index);
            });
            var flag=0;
            $(".btn-success").on("click", function () {
                var NewPWD=$(".NewPWD").val();
                var passwordNew=$(".confirm_password").val();

                if(NewPWD==''){
                    layer.msg("新密码为空");
                    return;
                }
                if(passwordNew==''){
                    layer.msg("确认密码为空");
                    return;
                }
                if(NewPWD!=passwordNew){
                    layer.msg("两次密码输入不一致");
                    return;
                }
                var userId = getStorage("userId");
                if (flag == 1) return;
                flag = 1;
                ajaxPost({
                    url: "userm/resetUserPassword",
                    data: {
                        userId:userId,
                        newPassword:passwordNew
                    },
                    successx: function (data) {
                        setTimeout(function(){
                            flag=0;
                        },200);
                        if (data.success) {
                            parent.layer.msg(data.message)                       
                            setTimeout(function () {
                                parent.layer.close(index);
                            }, 2000);
                            // setTimeout(function () {
                            //     window.location.href = "usermanage.html";
                            // }, 2200);
                        } else {
                            parent.layer.msg(data.message)
                        }
                    }
                })

            });
        });
    </script>
</body>
</html>
